package com.zjc.kafka.embedded;

import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.util.Properties;

@SpringBootApplication
public class EmbeddedKafkaMain implements CommandLineRunner {
    private static final int REPLICATION_FACTOR = 1;

    private static EmbeddedKafka kafka;

    public static void main(String[] args) {
        SpringApplication.run(EmbeddedKafkaMain.class, args);
    }

    @Override
    public void run(String... args) throws Exception {
        Properties serverProps = new Properties();
        serverProps.setProperty("delete.topic.enable", "true");

        kafka = new EmbeddedKafkaBuilder()
                .numServer(REPLICATION_FACTOR)
                .serverProperties(serverProps)
                .build().start();
        System.out.println(kafka.getBrokerConnectionString());
        System.out.println(kafka.getStandardProperties());
    }
}
